package com.example.yuejian.yuejian.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.bean.MasterClass;
import com.example.yuejian.yuejian.view.RoundImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/9/18.
 */

public class ClassAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{
    private Context mContext;;
    private List mDataList;
    public LayoutInflater mLayoutInflater;
    public ClassAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.inflate(R.layout.cardview_teacher_detail_class, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final MasterClass entity = (MasterClass) mDataList.get(position);
        if (null == entity)
            return;
        final ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.class_name.setText(entity.getClassname());
        viewHolder.class_follow_num.setText(entity.getNum()+"");
        if (!"".equals(entity.getPhoto()))
        {
            Picasso.with(mContext).load(entity.getPhoto()).into(viewHolder.class_image);
        }
        else
        {
            viewHolder.class_image.setImageResource(R.drawable.camera);
        }

        /*viewHolder.master_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, TeacherDetailActivity.class);
                intent.putExtra("master_id",entity.getId()+"");
                mContext.startActivity(intent);

            }
        });*/
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView class_name;
        RoundImageView class_image;
        //TextView master_type;
        TextView class_follow_num;
        ImageView imageView_follow;
        //LinearLayout master_detail;

        public ViewHolder(View itemView) {
            super(itemView);
            imageView_follow=itemView.findViewById(R.id.img_teacher_detail_class_heart);
            class_name = (TextView) itemView.findViewById(R.id.tv_teacher_detail_class_name);
            class_image = (RoundImageView) itemView.findViewById(R.id.img_teacher_detail_class_photo);
            //master_type = (TextView) itemView.findViewById(R.id.tv_home_teacher_type);
            class_follow_num= (TextView) itemView.findViewById(R.id.tv_teacher_detail_class_num);
            //master_detail=(LinearLayout)itemView.findViewById(R.id.cardview_home_teacher_detail);

        }
    }

}
